package Jumin_Test;

import java.util.Calendar;

public class JuminService {
	static boolean checkJumin(String jumin) {
		int a = 11 - ((Integer.parseInt(jumin.substring(0, 1)) * 2
				+ Integer.parseInt(jumin.substring(1, 2)) * 3
				+ Integer.parseInt(jumin.substring(2, 3)) * 4
				+ Integer.parseInt(jumin.substring(3, 4)) * 5
				+ Integer.parseInt(jumin.substring(4, 5)) * 6
				+ Integer.parseInt(jumin.substring(5, 6)) * 7
				+ Integer.parseInt(jumin.substring(6, 7)) * 8
				+ Integer.parseInt(jumin.substring(7, 8)) * 9
				+ Integer.parseInt(jumin.substring(8, 9)) * 2
				+ Integer.parseInt(jumin.substring(9, 10)) * 3
				+ Integer.parseInt(jumin.substring(10, 11)) * 4
				+ Integer.parseInt(jumin.substring(11, 12)) * 5) % 11);
		
		if (a == Integer.parseInt(jumin.substring(12, 13))) {
				return true;
		} else { return false; }
	}
	
	static String birth(String jumin1, String jumin2) {
		String birthYear = null;
		String birthMonth = null;
		String birthDay = null;
		
		switch(jumin2) {
		case "0" : case "9" : birthYear = "1800"; break;
		case "1" : case "2" : case "5" : case "6" : birthYear = "1900" ; break;
		case "3" : case "4" : case "7" : case "8" : birthYear = "2000"; break;
		}
		birthYear = Integer.toString(Integer.parseInt(birthYear)
				+ Integer.parseInt(jumin1.substring(0, 1)) * 10
				+ Integer.parseInt(jumin1.substring(1, 2)));
		
		birthMonth = Integer.toString(Integer.parseInt(jumin1.substring(2, 3)) * 10
				+ Integer.parseInt(jumin1.substring(3, 4)));
		
		birthDay = Integer.toString(Integer.parseInt(jumin1.substring(4, 5))* 10
				+ Integer.parseInt(jumin1.substring(5, 6)));
		return birthYear + "년 " + birthMonth + "월 " + birthDay + "일";
	}
	
	static String gender(String jumin) {
		return Integer.parseInt(jumin) % 2 == 0 ? "여성" : "남성" ;
	}
	
	static String country(String jumin) {
		if (Integer.parseInt(jumin) >= 5 && Integer.parseInt(jumin) <= 8) {
			return "외국인";
		} else { return "내국인"; }
	}
	
	static String birthArea(String jumin) {
		String area = null;
		switch(jumin) {
		case "00" : case "01" : case "02" : case "03" :
		case "04" : case "05" : case "06" : case "07" : case "08" :
			area = "서울"; break;
		case "09" : case "10" : case "11" : case "12" :
			area = "부산"; break;
		case "13" : case "14" : case "15" :
			area = "인천"; break;
		case "16" : case "17" : case "18" :
			area = "경기 주요 도시"; break;
		case "19" : case "20" : case "21" : case "22" :
		case "23" : case "24" : case "25" :  
			area = "기타 경기도"; break;
		case "26" : case "27" : case "28" : case "29" : 
		case "30" : case "31" : case "32" : case "33" : case "34" :
			area = "강원도"; break;
		case "35" : case "36" : case "37" : case "38" : case "39" : 
			area = "충청북도"; break;
		case "40" : case "41" : case "42" : case "43" : case "44" :
		case "45" : case "46" : case "47" : 
			area = "충남/대전/세종"; break;
		case "48" : case "49" : case "50" : case "51" : case "52" : 
		case "53" : case "54" :
			area = "전라북도"; break;
		case "55" : case "56" : case "57" : case "58" : case "59" : case "60" :
		case "61" : case "62" : case "63" : case "64" : case "65" : case "66" :
			area = "전남/광주"; break;
		default :
			area = "경남/경북/울산"; break;
		}
		return area;
	}
	
	static String checkAge(String jumin1, String jumin2) {
		Calendar ca = Calendar.getInstance();
		int year = 0;
		switch (jumin2) {
		case "0" : case "9" : year = 1800; break;
		case "1" : case "2" : case "5" : case "6" : year = 1900; break;
		case "3" : case "4" : case "7" : case "8" : year = 2000; break;
		}
		year += (Integer.parseInt(jumin1.substring(0, 1)) * 10
				+ Integer.parseInt(jumin1.substring(1, 2))); 
		return Integer.toString(ca.get(Calendar.YEAR) - year + 1);
	}
}
